#!/bin/sh
#
# This script fake scrapes the internode
# unmetered radio site, downloads all pls files
# and renames to the station name.
#
cd /usr/media-library/audio/radio/
rm index.html index.wget *pls *m3u* *strm .977*
wget http://www.internode.on.net/residential/entertainment/broadband_radio/
grep -o 'http://[a-z./0-9]*m3u' index.html > index.wget
wget -i index.wget


for PLAYLIST in *.m3u
do
	# Ready titles for renaming files
	TITLE=`grep "#EXTINF*" "${PLAYLIST}" | sed s/\#EXTINF\:\-1\,//`
	TITLE=`echo ${TITLE} | sed s/\\:/\ -/`

	# Get Direct Link
	DIRECT=`grep "://" "${PLAYLIST}"`

	# Generate Bookmarks list for Streamer on iPhone
	URL=`grep "File1*" "${PLAYLIST}" | sed s/File1\=//`
	echo "# 1 ${TITLE}" >> playlist1.m3u
	echo "${URL}" >> playlist1.m3u

        echo ${TITLE}
	echo "${DIRECT}" > "${TITLE}.strm"

done

rm *.m3u*
